﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BLL.SysManage
{
    public class T_PUB_PROJECTTYPE
    {
        private readonly DALL.SysManage.T_PUB_PROJECTTYPE dal = new DALL.SysManage.T_PUB_PROJECTTYPE();


        /// <summary>
        /// 智能提示项目类型名称
        /// </summary>
        /// <returns></returns>
        public DataSet GetProjectTypeName()
        {
            return dal.GetProjectTypeName();
        }

        /// <summary>
        /// 递归查询
        /// </summary>
        /// <param name="strPID"></param>
        /// <returns></returns>
        public List<Model.SysManage.T_PUB_PROJECTTYPE> GetAllListArry(string strPID)
        {
            return dal.GetAllListArry(strPID);
        }

        /// <summary>
        /// 获得项目的类型路径
        /// </summary>
        /// <param name="strProjects"></param>
        /// <returns></returns>
        public List<string> GetProjectTypePath(string strProjects)
        {
            string strarrid = "";
            if (strProjects.IndexOf(",") >= 0)
            {
                string[] strArry = strProjects.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in strArry)
                {
                    strarrid = strarrid + string.Format("'{0}'", item) + ",";
                }
                if (strarrid.Length > 0)
                {
                    strarrid = strarrid.Substring(0, strarrid.Length - 1);
                }
            }
            else
            {
                strarrid = "'" + strProjects + "'";
            }
            string strWhere = string.Format(" and p.PROJECT_ID in({0}) ", strarrid);
            return dal.GetProjectTypePath(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.SysManage.T_PUB_PROJECTTYPE> GetNotNullList()
        {
            string strwhere = " is_null='1'";
            return GetModelList(strwhere);
        }

        #region  Method

        /// <summary>
        /// 获得下降所有项目
        /// </summary>
        /// <param name="strPIPD">父ID</param>
        /// <param name="strNmae">名称</param>
        /// <returns></returns>
        public List<Model.SysManage.T_PUB_PROJECTTYPE> GetnextProject(string strPIPD, string strNmae)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  1>0 ");
            if (strPIPD != "" && strPIPD != null)
            {
                strSql.Append(string.Format(" and PARENT_ID='{0}'", strPIPD));
            }
            if (!string.IsNullOrEmpty(strNmae))
            {
                strSql.Append(string.Format(" and PROJECTTYPE_NAME like'%{0}%'", strNmae));
            }
            return GetModelList(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.SysManage.T_PUB_PROJECTTYPE model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.SysManage.T_PUB_PROJECTTYPE model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int PROJECTTYPE_ID)
        {

            return dal.Delete(PROJECTTYPE_ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.SysManage.T_PUB_PROJECTTYPE GetModel(int PROJECTTYPE_ID)
        {

            return dal.GetModel(PROJECTTYPE_ID);
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.SysManage.T_PUB_PROJECTTYPE> GetModelList(string strWhere)
        {
            return dal.GetListArray(strWhere);
        }
        #endregion  Method
    }
}
